var Main = Vue.component('main', function (resolve, reject) {
    axios.get('views/main/main.html?timestamp='+timestamp).then(function (res) {
        resolve({
            template: res.data,
            data() {
                return {
                    loading:false,
                    sysName: '后台管理系统',
                    menuData: [],
                    collapsed: false,
                    showChangePwdWin:false,
                    cpForm:{},
                    formLabelWidth:'120px',
                    helloInfo: '你好，'+JSON.parse(sessionStorage.loginUser).name,
                    mainLogo2:MAIN_INFO_CONFIG.mainLogo2,
                    permssion:{}
                }
            },
            methods: {
                initMenu: function () {
                    for (let i in this.$router.options.routes) {
                        let root = this.$router.options.routes[i]
                        if (root.hidden)
                            continue
                        let children = []
                        for (let j in root.children) {
                            let item = root.children[j]
                            if (item.hidden)
                                continue
                            children.push(item)
                        }

                        if (children.length < 1)
                            continue
                        this.menuData.push(root)
                        root.children = children;
                        this.permssion=   CommonUtils.getPermissionJson();
                    }
                },
                //折叠导航栏
                collapse: function () {
                    this.collapsed = !this.collapsed;
                },
                showMenu: function (i, status) {
                    this.$refs.menuCollapsed.getElementsByClassName('submenu-hook-' + i)[0].style.display = status ? 'block' : 'none';
                },
                getPermision(item) {
                    var enabeld = item['enabeld'];
                    var flag = false;
                    if (enabeld) {
                        enabeld.forEach(k => {
                            if (this.permssion[k]) {
                                flag = true;
                            }
                        });
                    } else {
                        flag = true;
                    }
                    return flag;
                },
                loginOut(event){
                    this.$router.push({ path: '/login' });
                },
                changePwd(event){

                    this.loading = true;
                    setTimeout(() => {
                        this.loading = false;
                    }, 2000);

                    httpInvoker.post(APIs.auser.changePwd,this.cpForm).then(res =>{
                        this.loading = false;
                        if(res.status == 200 && res.data.status == '00'){
                            this.$alert('修改成功，请重新登录', '', {
                                confirmButtonText: '确定',
                                callback: action => {
                                    this.$router.push({ path: '/login' });
                                }
                            });
                        }else{
                            this.$alert(res.data.msg, '', {
                                confirmButtonText: '确定'
                            });
                        }
                    })
                }

            },
            mounted: function () {
                this.initMenu()
            }
        })
    })
})



